
		scope.getUserInfo = function(user){
			if( user != null ){
				scope.user = user;
				if( scope.user.userXP == null ){
					scope.user.userXP = "images/profile.jpg";
				};
			}else{
				http.post("GetUserInfo.action").success(function(response) {
					scope.user = response;
					if( scope.user.userXP == null ){
						scope.user.userXP = "images/profile.jpg";
					};					
				});
			}
			shutAllPages(scope);
			scope.userInfoShow=true;
			
		};		
		
		scope.pageAccountManagement = function(page){
			$("input[name='slectAll']").prop("checked",false);
			$("input[name='userbox']").prop("checked",false);
			console.log("page" + page);
			var maxCount = 10;
			var min = ( page - 1 ) * maxCount;
			if( min < 0 || min >= scope.tempAccountList.length )
				return ;
			scope.beanList = [];
			for( var i = 0; i < maxCount && ( min + i + 1 ) <= scope.tempAccountList.length;i++ ){
				scope.beanList[i] = scope.tempAccountList[min + i];
			}
			scope.accountManagementPage = page;
		}
		
		
		scope.accountManagement = function(onsuccess){
			
			http.post("GetAllUserInfo.action").success(function(response) {			
				scope.tempAccountList = response;
				scope.accountManagementPage = 1;
				scope.beanList = [];
				for( var i = 0; i < 10 && i < scope.tempAccountList.length ; i++ ){
					scope.beanList[i] = scope.tempAccountList[i];
				}
				onsuccess();
			});
			$("input[name='slectAll']").prop("checked",false);
			$("input[name='userbox']").prop("checked",false);
			shutAllPages(scope);
			scope.accManShow=true;
		};

		scope.insertUser = function(){
			var userId = document.getElementsByName("userId")[0].value;
			var userPass = document.getElementsByName("userPass")[0].value;
			var userName = document.getElementsByName("userName")[0].value;
			var userPermission = document.getElementsByName("userPermission");
			var permissions = new Array();
			for(var i = 0;i < userPermission.length;i++){
				if( userPermission[i].checked == true ){
					permissions.push(userPermission[i].value);
				}
				
			}
			
			
			if( permissions.length == 0 ){
				alert("请至少选择一个权限");
				return;
			}
			http.post("InsertUserInfo.action", {"userId" : userId, "userPass" : userPass, "userName" : userName, "userPermission" : permissions}).success(function(response) {
				onsuccess = function(){
					var i = parseInt(scope.tempAccountList.length / 10);
					if(  scope.tempAccountList.length % 10 == 0 ){
						scope.pageAccountManagement(i);
					}
					else{
						scope.pageAccountManagement(i+1);
					}
				}
				scope.accountManagement(onsuccess);
				
				
				
					
				return;
				}); 
			
		};
		
		scope.deleteUser = function(userId){
			var userIdList = new Array();
			if (userId != null) {
				userIdList.push(userId);
			} else {
				$("input[name='userbox']:checked").each(function() {
					userIdList.push(this.value);
				});
			}
			if (userIdList.length <= 0) {
				alert("请至少选择一个需要删除的项！");
				return;
			}
			http.post("DeleteUser.action", { "userIdList" : userIdList }).success(function(response) {
				if (response.indexOf("success") > -1) {
					alert("操作成功！");
					onsuccess = function(){
						var i = parseInt((scope.tempAccountList.length - 1) / 10);
						console.log(i);
						if(  scope.tempAccountList.length % 10 == 0 ){
							scope.pageAccountManagement(i - 1);
						}
						else{
							scope.pageAccountManagement(i);
						}
					}
					scope.accountManagement(onsuccess);
					return;
				} else {
					alert(response);
				}
			}).error(function(response){
				alert(response);
			});
		};
		
		scope.changUserInfoPage = function(){
			scope.temp = scope.user;
			shutAllPages(scope);
			scope.changeInfoShow = true;			
		};
		
		scope.changUserInfo = function(){
			http.post("UpdateUserInfo.action", { "tempUser" : scope.temp }).success(function(response) {
				scope.getUserInfo(response);
			});
			
		};
		
		
		
		